<?php

class InlineLog {
	/**
	 * 
	 *
	 * @return Zend_Log
	 */
	public static $instance;
	
	public static function log($str){
		self::getInstance()->debug($str);
	}
	
	public static function red_log($str){
		self::getInstance()->debug("<span style='color:red'>".$str."</span>");
	}
	
	public static function gray_log($str){
		self::getInstance()->debug("<span style='color:gray'>".$str."</span>");
	}
	
	public static function blue_log($str){
		self::getInstance()->debug("<span style='color:blue'>".$str."</span>");
	}
	
	public static function green_log($str){
		self::getInstance()->debug("<span style='color:green'>".$str."</span>");
	}
	
	/**
	 * 
	 *
	 * @return Zend_Log
	 */
	public static function getInstance(){
		if(!self::$instance){
			self::$instance = self::createInstance();
		}
		return self::$instance;
	}
	
	/**
	 * 创建log
	 *
	 * @param String $type
	 * @return Zend_Log
	 */
	private static function createInstance(){
		$logger = new Zend_Log();
		$writer = new Zend_Log_Writer_Stream('php://output');
		$formatter = new Zend_Log_Formatter_Simple('[%priorityName%] : %message%' . PHP_EOL);
		$writer->setFormatter($formatter);
//		$filter = new Zend_Log_Filter_Priority(Zend_Log::CRIT);
//		$logger->addFilter($filter);
		$logger->addWriter($writer);
		return $logger;
	}	
	
	public static function disable(){
		$filter = new Zend_Log_Filter_Priority(Zend_Log::CRIT);
		self::getInstance()->addFilter($filter);
	}
}